from django.utils.deprecation import MiddlewareMixin
from web import models

class AuthMiddleware(MiddlewareMixin):
    """定义了一个检查是否登录的中间键"""
    def process_request(self, request):
        """ 如果用户登录成功，则在request中赋值 """
        user_id = request.session.get("user_id",0) # 获取sessin中的值,如果没有获取到就赋值为0

        user_object = models.UserInfo.objects.filter(id=user_id).first() # 查看数据库中有没有值
        request.tracer = user_object
